package main

import (
	"github.com/veandco/go-sdl2/img"
	"github.com/veandco/go-sdl2/sdl"
)

const (
	W = 670
	H = 620
)

func main() {
	sdl.Init(sdl.INIT_EVERYTHING)
	defer sdl.Quit()

	window, _ := sdl.CreateWindow("test", sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED,
		W, H, sdl.WINDOW_SHOWN)
	defer window.Destroy()

	renderer, _ := sdl.CreateRenderer(window, -1, sdl.RENDERER_ACCELERATED)
	defer renderer.Destroy()
	renderer.SetDrawColor(128, 128, 128, 255)

	pngImage, _ := img.Load("../asserts/image/texture.png")

	texture, _ := renderer.CreateTextureFromSurface(pngImage)
	pngImage.Free()
	defer texture.Destroy()

	src := sdl.Rect{0, 0, 200, 200}
	dst := sdl.Rect{0, 0, W, H}

	running := true
	for running {
		for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
			switch event.(type) {
			case *sdl.QuitEvent:
				println("Quit")
				running = false
				break
			}
		}
		renderer.Clear()
		renderer.Copy(texture, &src, &dst)
		renderer.Present()
		sdl.Delay(16)
	}
}
